package com.chujian.framework.sync.handler;

import com.chujian.framework.sync.SyncData;
import com.chujian.framework.sync.SyncDataFactory;
import com.chujian.framework.sync.SyncConst;

import java.lang.reflect.Method;

// mybatis.IService
public class UpdateByIdHandler implements ISyncMethodHandler {

    @Override
    public String supportMethod() {
        return SyncConst.METHOD_UPDATE_BY_ID;
    }

    @Override
    public SyncData creSyncData(Method method, Object[] args, Object returnValue, Object target) {
        // default boolean updateById(T entity)
        // 第一个参数为 修改 的参数
        Object entity = args[0];

        Object syncObj = selectOne(entity, target);
        return SyncDataFactory.creSingleItemSyncData(SyncConst.CHANGE_TYPE_UPDATE, target, syncObj);

    }
}
